import java.util.Arrays;
import java.util.List;

public class Client {
    public static void main(String[] args) throws InterruptedException {
        final PaperList listOfRainy = new PaperList("Rainy",
                Arrays.asList(
                        new Thesis("Science"),
                        new ConferencePaper("Science"),
                        new JournalPaper("Technology")
                )
        );

        // 设置顺序选择策略
        listOfRainy.setStrategy(new SequentialSelectionStrategy());

        final List<Student> students = Arrays.asList(
                new Student("Cloudy", 1, PaperType.Thesis),
                new Student("Sunny", 1, PaperType.JournalPaper),
                new Student("Windy", 2, PaperType.Any)
        );

        for (Student student : students) {
            new Thread(() -> {
                try {
                    List<Paper> selected = listOfRainy.selectPaper(student);
                    System.out.println(student.getName() + "选择了: " + selected);
                } catch (NoEnoughPapersException | IllegalArgumentException e) {
                    System.out.println(e.getMessage());
                }
            }).start();
        }

        Thread.sleep(1000);

        // 使用Visitor查询结果
        StudentCountVisitor visitor = new StudentCountVisitor();
        listOfRainy.getSelectionResult().accept(visitor);
        System.out.println("\n已选论文学生数: " + visitor.getCount());
        System.out.println("最终选择结果:");
        System.out.println(listOfRainy.getSelectionResult());
    }
}